﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using Meqs.Logic.Interface;
using System.Collections.Generic;

public partial class Credit_Teacher_RuleSettings_SettingEvalDefault : ContainerBasePage
{
    private CauseFormula cf = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Repeater1.DataSource = GetEvalList();
            Repeater1.DataBind();
            cf = new CauseFormula(SchoolMark,0);
            txtDayLimit.Text = cf.DayLimit.ToString();
        }
    }


    /// <summary>
    /// 获取当前学年学期的带有课程名的学分记录
    /// </summary>
    /// <returns></returns>
    private List<VStuCauseEvalHistory> GetEvalList()
    {
        int schoolYear = SchoolCommon.Sch_SchoolInfo.SchoolYear;
        int term = SchoolCommon.Sch_SchoolInfo.SchoolTerm;
        string schoolMark = Common.GetConstSchoolMark();

        IStuCauseEvalHistoryLogic logic = Container<IStuCauseEvalHistoryLogic>.Instance;
        //判断当前学年学期是否有数据，没有则添加
        if (!ValidateIsNewTerm())
        {
            //TODO:
           // logic.CreateNewTermHistory(schoolYear,term);
        }

        List<VStuCauseEvalHistory> list = (List<VStuCauseEvalHistory>)logic.FindByCauseName(schoolMark, schoolYear, term);

        //foreach (VStuCauseEvalHistory cl in list)
        //{
        //    StuCasueHistoryView mhv = new StuCasueHistoryView();
        //    mhv.EvalType = 3;
        //    mhv.Attribute = cl.Attribute;
        //    mhv.Caption = cl.Caption;
        //    mhv.KeyWord = cl.KeyWord;
        //    mhv.ManagerID = cl.ManagerID;
        //    mhv.RID = cl.RID;
        //    mhv.SchoolMark = cl.SchoolMark;
        //    mhv.SchoolYear = cl.SchoolYear;
        //    mhv.Site = cl.Site;
        //    mhv.Status = cl.Status;
        //    mhv.Term = cl.Term;
        //    mhvs.Add(mhv);
        //}

        return list;
    }

    /// <summary>
    /// 验证当前是否是新学年学期
    /// </summary>
    /// <returns></returns>
    private bool ValidateIsNewTerm()
    { 
        int schoolYear = SchoolCommon.Sch_SchoolInfo.SchoolYear;
        int term = SchoolCommon.Sch_SchoolInfo.SchoolTerm;

        IStuCauseEvalHistoryLogic logic = Container<IStuCauseEvalHistoryLogic>.Instance;
        Hashtable table = new Hashtable();
        table.Add("SchoolMark", Common.GetConstSchoolMark());
        table.Add("SchoolYear",SchoolCommon.Sch_SchoolInfo.SchoolYear);
        table.Add("Term",SchoolCommon.Sch_SchoolInfo.SchoolTerm);

        List<StuCauseEvalHistory> list = ( List<StuCauseEvalHistory>)logic.FindAll(table);

        if (list.Count > 0)
            return true;
        else
            return false;

    }

    [System.Web.Services.WebMethod]
    public static int SaveSure(string[] ids)
    {
        IStuCauseEvalHistoryLogic logic = Container<IStuCauseEvalHistoryLogic>.Instance;
        string strIds = string.Join(",", ids);
        int n = logic.UpdateStatus(Common.GetConstSchoolMark(), strIds,SchoolCommon.Sch_SchoolInfo.SchoolYear, SchoolCommon.Sch_SchoolInfo.SchoolTerm);
        return n;
    }


    [System.Web.Services.WebMethod]
    public static int SaveDayLimit(double dayLimit)
    {
        StuCauseCipher scc = new StuCauseCipher();
        scc.KeyWord = "DayLimit";
        scc.Paramer = dayLimit;
        scc.SchoolMark = SchoolMark;
        return Container<IStuCauseCipherLogic>.Instance.UpdateByKey(scc);
        
    }
 
    protected void btnBind_Click1(object sender, EventArgs e)
    {
        Repeater1.DataSource = GetEvalList();
        Repeater1.DataBind();
    }
}
